using System.Collections;
using System.Collections.Generic;
using System.Xml.Serialization;
using UnityEngine;

public class moveControll : MonoBehaviour
{
    public float speed;
    private Rigidbody2D rb;
    private int maxHealth = 5;
    private int currentHealth;//当前血量
    public int MaxHealth { get { return maxHealth; } }
    public int CurrentHealth { get { return currentHealth; } }

    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        currentHealth = 2;
        isTime = true;
        times = 2f;
    }
    void FixedUpdate()
    {
        float move1 = Input.GetAxis("Horizontal");
        float move2 = Input.GetAxis("Vertical");
        Vector2 move3 = new Vector2(move1, move2) * speed;
        Vector2 position = rb.position + move3 * Time.deltaTime;
        rb.MovePosition(position);
    }

    public void pullHealth(int count)
    {
        if (currentHealth < maxHealth)
        {
            currentHealth = Mathf.Clamp(currentHealth + count, 0, 5);
        }
    }
    public void deleteHealth(int count)
    {
        if (currentHealth > 0)
        {
            currentHealth = Mathf.Clamp(currentHealth - count, 0, 5);
        }
        

    }
    private bool isTime;
    private float times;
    private float time = 2;
    
    public void wudi()
    {
        if (isTime)
        {
            times -= Time.deltaTime;
            if (times < 0)
            {
                deleteHealth(1);
                times = time;
                isTime = true;
            }
        }
        
    }
}
